package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.CompetModel;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.RegularUtil;
import com.banshuibao.bsb_android.util.XToast;

public class CheckInActivity extends BaseActivity implements View.OnClickListener {

    private TextView commit,sign;
    private EditText realName,numberCard;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_in);
        initView();
    }

    public void initView(){
        setTitleText("培训登记");
        sign = findViewById(R.id.sign);
        sign.getPaint().setFakeBoldText(true);
        commit = findViewById(R.id.commit);
        commit.getPaint().setFakeBoldText(true);
        realName = findViewById(R.id.realeName);
        numberCard = findViewById(R.id.numberCard);
        commit.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.commit:
                getData();
                break;
        }
    }

    public void getData(){
        String name = realName.getText().toString().trim();
        String card = numberCard.getText().toString().trim();
        if(TextUtils.isEmpty(name)){
            XToast.showToast(this,"请输入姓名");
            return;
        }else{
            if(!RegularUtil.isLegalName(name)){
                XToast.showToast(this,"请输入正确的名字");
                return;
            }
        }
        if(TextUtils.isEmpty(card)){
            XToast.showToast(this,"请输入身份证号");
            return;
        }else{
            if(!RegularUtil.isLegalId(card)){
                XToast.showToast(this,"请输入正确的身份证号");
                return;
            }
        }
        requestNet(name,card);
    }

    public void requestNet(String name,String numberId){
        CompetModel competModel = new CompetModel();
        competModel.setId(numberId);
        competModel.setName(name);
        HttpUtil.doPost(Constants.Url.SIGN_COMPETITION, competModel, new HttpResponse(this) {
            @Override
            public void onResult(Object obj) {
                XToast.showToast(CheckInActivity.this,"登记成功");
                IntentManager.goCheckOkActivity(CheckInActivity.this);
                finish();
            }
        });

    }
}
